package com.spider.moudle.pool;
import java.util.LinkedList;

/**
 * Created by stanfordh on 09/27/18.
 */
public class Pool<T> {

    private static Pool instance = new Pool();

    private final LinkedList<T> pool = new LinkedList<>();

    private Pool() {
    }


    private static Pool getInstance() {
        return instance;
    }


    public void add(T t) {
        if(t != null) {
            synchronized(pool) {
                pool.add(t);
                pool.notifyAll();
            }
        }
    }

    public T get() throws InterruptedException {
        synchronized(pool) {
            while (pool.isEmpty()) {
                pool.wait();
            }
            return pool.removeFirst();
        }
    }


}
